home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / pacdoc / ftl0.doc < prev    next >
Text File  |  1990-09-05  |  63KB  |  1,582 lines

  1.  
  2.  
  3.  
  4.         Revised 27 AUG 90 - Minor type corrections, section 9 added.
  5.  
  6.  
  7.  
  8.                                 
  9.  
  10.                   Pacsat Protocol: File Transfer Level 0
  11.                                                 
  12.                             Jeff Ward, G0/K8KA
  13.                            Harold E. Price, NK6K
  14.                                                
  15.  
  16.                                  ABSTRACT
  17.  
  18.  
  19.      This document specifies Version 0 of the File Transfer Level 0 
  20.      (FTL0) protocol designed for use on store-and-forward satellites 
  21.      (PACSATs).  The protocol provides procedures for transferring 
  22.      binary files to and from a server computer using an error-
  23.      corrected communication link.  
  24.  
  25.      Further to basic file transfer facilities, FTL0 provides file 
  26.      selection and directory procedures.  Because a server may contain 
  27.      many files, only some of which are of interest to each client, the 
  28.      client may ``select'' a subset of the server's files.  Subset 
  29.      selection is based on a flexible logical equation involving a 
  30.      large number of file characteristics.  The scope of directory 
  31.      requests or file download requests can be limited to those files 
  32.      currently selected.
  33.  
  34.      This protocol is designed to work specifically with files in which 
  35.      the actual ``data'' or ``body'' of the file is preceded by a 
  36.      standard ``header'', specified in the PACSAT File Header Defini-
  37.      tion document.  
  38.  
  39.  
  40. 1.0 BACKGROUND
  41.  
  42. Terrestrial packet-radio bulletin board systems (PBBSs) in the amateur radio 
  43. service generally provide a character-based, human-to-machine interface 
  44. through which user's command the PBBS software.  A similar interface has been 
  45. adopted on the FUJI-OSCAR store-and-forward (PACSAT) satellites.  Through the 
  46. character-based interface, the user selects messages, requests directory list-
  47. ings, and views, stores and deletes messages.  All messages are stored as 
  48. ASCII text files, and the PBBS maintains a directory entry for each message. 
  49. The directory contains message source, destination, title, time of storage, 
  50. size, and status.  The PBBS also stores data relating to each user station, 
  51. such as the most recent message each user station has listed or viewed.  
  52.  
  53. Since messages and PBBS commands contain only ASCII characters, the user's 
  54. station equipment can be as basic as an ASCII terminal connected to a terminal 
  55. node controller (TNC). This simplicity makes the current system attractive, 
  56. and has lead to its widespread adoption.  
  57.  
  58. These current PBBS systems also have several drawbacks, stemming from the 
  59. text-based user interface and from the lack of a flexible, informative message 
  60. header. All messages must be in ASCII, only simple ASCII message headers are 
  61. supported, and only a few search-keys are provided for message selection.
  62.  
  63. These limitations are particularly damaging in the PACSAT environment, where 
  64. the user base is large, the communications bandwidth is restricted, and the 
  65. onboard computer software must be compact and highly reliable.  
  66.  
  67. The File Transfer Level 0 protocol defined here, and the PACSAT File Header 
  68. Definition presented elsewhere, combine to provide a PBBS protocol suite which 
  69. overcomes the limitations of the current text-based protocols.  
  70.  
  71. The proposed protocols are based on a different model of a store-and-forward 
  72. messaging network. The PBBS is a ``server'' and the user stations are ``cli-
  73. ents''. The server stores files, each of which contains a ``header'' of known 
  74. format, followed by a ``body''. The header holds information about the file 
  75. and about the body, including (but not limited to) the file length, creation 
  76. date, destination, source, keywords, and body compression technique. The body 
  77. is the data portion of the file, which can be any digital information, e.g. 
  78. binary, ASCII, FAX, digitised voice, etc. 
  79.  
  80. The user station, or ``client'' is assumed to be under computer control.  The 
  81. client sends files to the server and receives files from the server over an 
  82. AX.25 data link, using an automated server/client file transfer protocol. The 
  83. client software interprets and displays the file headers and bodies for the 
  84. human user.  When the user wishes to upload a file to the server, client 
  85. software must add suitable standardized header fields to the file, and it may 
  86. also compress or otherwise prepare the file for uploading.
  87.  
  88. Each user is generally interested in only a small subset of the files avail-
  89. able on a server.  Using a powerful selection facility the client can select 
  90. an interesting subset of the files on the server for directory listing or 
  91. downloading. The selection can be based on any combination of items in the 
  92. file header, thus user's software can assure that the user only ``sees'' files 
  93. which are likely to be of interest.
  94.  
  95. The server might not keep a user data base, and the client software must store 
  96. any important information concerning the user's last server session.  For 
  97. example, to implement a command equivalent to the PBBS command ``list new'', 
  98. the client software must store the message number, or date and time of the of 
  99. the last access to the server.
  100.  
  101. Since this protocol is also useful for terrestrial servers, we use the terms 
  102. ``server'' and ``client'' throughout, instead of ``PACSAT'' and ``groundsta-
  103. tion''.  The protocol does depend on the presence of the standard PACSAT file 
  104. header, this is to implement file locking or other features.  A version of the 
  105. protocol that can be used by terrestrial stations without the PACSAT headers 
  106. is under consideration.
  107.  
  108. FTL0 includes several features that make the protocol somewhat more complex 
  109. than some others in use in the amateur packet network.  These features include 
  110. simultaneous bidirectional file transfer, file locking by forwarding gateways, 
  111. and multiple destination forwarding.   As is sometimes the case, the actual 
  112. implementation is smaller than the specification.  The pseudo-code provided in 
  113. Appendix B and C show that the protocol is actually quite straightforward.  
  114. The authors also plan to make the prototype source code available on a public 
  115. BBS.
  116.  
  117.  
  118. 1.1 FTL0
  119.  
  120. The FTL0 protocol can support full-duplex message transfer, in which a single 
  121. data link (AX.25 connection) is used simultaneously to upload one file and to 
  122. download another file.  Client software does not necessarily have to implement 
  123. this capability.  The protocol provides for continuation of uploads and down-
  124. loads interrupted by loss of the data link (generally caused by LOS at a 
  125. satellite groundstation), and includes confirmation handshakes at all critical 
  126. stages of file transfer.  An FTL0 file transfer should withstand interruption 
  127. at any stage.
  128.  
  129. It is assumed that the client software uses the transparent mode of an AX.25 
  130. TNC and that the AX.25 connection represents an error-free channel.  Other 
  131. data links which present an ordered, error corrected byte stream may be used.  
  132. Although the link may be terminated at any time, it is assumed that the link 
  133. will not pass corrupted or out-of-order bytes, and that processes at both ends 
  134. of the link will be notified if the link is terminated.  The PACSAT File 
  135. Header standard provides overall checks on the integrity of files transferred 
  136. to and from fully-compliant servers.
  137.  
  138. FTL0 commands and responses form simple ``packets'' inside the byte stream on 
  139. the communications link.  Specifically, in AX.25, an FTL0 packet may be trans-
  140. mitted in one or more AX.25 I frames; neither the server nor the client is 
  141. aware of the AX.25 I frame boundaries.  The packet format is described in 2.0 
  142. below.
  143.  
  144. 1.2 Associated Documents
  145.  
  146. PACSAT Data Specification Standards defines the meaning of data types and 
  147. structures within this specification.
  148.  
  149. The PACSAT File Header Definition defines the file header fields which must be 
  150. pre-pended to files before uploading to a fully-compliant FTL0 server.  (FTL0 
  151. procedures for terrestrial servers without PACSAT file headers are under 
  152. development.)
  153.  
  154.  
  155. 1.3 Terminology
  156.  
  157. server     is the PACSAT or the PBBS.
  158. client     is the user station.
  159. commands   are transmitted from the client to the server
  160. responses  are transmitted from the server to the client
  161. uplink     is data flow from the client to the server
  162. downlink   is data flow from the server to the client
  163. packet     is a sequence of bytes as defined in 2.0 below
  164. frame     is an AX.25 level 2 I frame
  165. data link  generally an AX.25 level 2 link, but may be a link using any 
  166. protocol which provides an ordered, error-checked, data transparent byte 
  167. stream.
  168.  
  169. 1.4 Overview of Operation
  170.  
  171. To allow simultaneous uploading and downloading, FTL0 clients and servers 
  172. implement two state machines.  One is related to file uploads, and the second 
  173. to all other possible commands.  FLT0 is not symmetric; the protocol state 
  174. machines implemented by the server are necessarily different from those imple-
  175. mented by the clients.
  176.  
  177. Dividing the data stream into packets allows for modular software implementa-
  178. tion and the multiplexing of commands and data on a single data link.  The 
  179. packet format is simple.  Every packet begins with 2 bytes of control informa-
  180. tion, which can be followed by 0 to 2047 bytes of data.  The packet may arrive 
  181. in many AX.25 I frames.  No packet synchronization or checksumming is provid-
  182. ed, since the data link (AX.25 connection) provides a notionally error-free 
  183. connection.  Full file error checks are performed at the completion of file 
  184. transfers.
  185.  
  186. It is assumed that neither the client software nor the server software is 
  187. aware of or can control data link (AX.25) frame boundaries.
  188.  
  189. A FTL0 session starts when an data link is established between the server and 
  190. the client.  The server will send a LOGIN response when the connection is 
  191. established.  
  192.  
  193. To allow the user to specify a group of files for directory listings or down-
  194. loading, the client software implement may implement menus or some other user 
  195. interface.
  196.  
  197. Once the user has indicated the desired files, the client software converts 
  198. the user's preferences into an equation , such as
  199.  
  200. ( (SOURCE = "G0K8KA*") && (KEYWORD = "*FTL0*") ) && (FILE_NUMBER > 3215).   
  201.  
  202. And then encodes the equation in a postfix, binary format as a SELECT command.  
  203. When the server receives a SELECT command it builds a list of files for which 
  204. the equation evaluates to TRUE.  As a response to the SELECT command, the 
  205. server informs the client how many files are in the selection list.
  206.  
  207. When the client sends a one of the directory commands, the server responds by 
  208. transmitting directory information for the next 10 files on the selected list. 
  209. Each subsequent directory command results in the server transmitting directory 
  210. information for a further 10 files from the selection list, until the list is 
  211. exhausted.  
  212.  
  213. Specific files or files from the selection list may be requested by the client 
  214. for downloading.  The download procedure consists of two command/response 
  215. cycles.  On the first cycle, the client requests the file and the server 
  216. responds by transmitting the file as a series of DATA packets followed by an 
  217. END_OF_DATA packet.  The server then waits for the client to acknowledge re-
  218. ceipt of the file.  When the server receives the acknowledgement, it transmits 
  219. a final handshake and the download is finished.
  220.  
  221. To upload a file to the server, the client sends an UPLOAD command telling the 
  222. server how large the file is.  The server responds with a handshake which 
  223. either tells the client to abort or to proceed.  If instructed to proceed, the 
  224. client sends the entire file as a series of DATA packets followed by an 
  225. DATA_END packet.  The server receives the entire file, and then either ac-
  226. knowledges the transfer or sends an error indication.
  227.  
  228. Because  PACSAT may go over the horizon in the midst of a  transaction,  down-
  229. loading and uploading can be continued during several sessions with the serv-
  230. er.  When a download is interrupted, the client must retain the file offset at 
  231. which communications was interrupted.  For interrupted uploads, the server 
  232. stores the appropriate offset.
  233.  
  234. 1.5 File Identification
  235.  
  236. Although servers may identify files using some kind of system file name 
  237. (PACSATs use the MS-DOS standard of an 8 character body and a 3 character 
  238. extension), FTL0 does not use server file names to identify files.  Instead, 
  239. the server assigns every file a 32-bit file number.  This is to insure that 
  240. two files with different contents but the same name will never be confused.  
  241. Thus, every message which a user uploads to PACSAT (or another FTL0 server) 
  242. will have a unique identifier.
  243.  
  244. 1.6 Gateway Procedures
  245.  
  246. Some messages on PACSAT will be destined for gateway stations which will 
  247. introduce the messages into other networks.  It is essential that only one 
  248. gateway download and relay each message.  To accommodate this, FTL0 provides 
  249. locked downloads.  Only one gateway at a time can perform a locked download of 
  250. a given file for a given destination.  If a locked download is interrupted, 
  251. this will be indicated in the PACSAT File Header of the file, so that other 
  252. gateways can tell when a file is in the process of being delivered.  
  253.  
  254. PACSAT File Headers allow files with multiple destinations, and separate locks 
  255. are implemented for each destination.  See Appendix A for further information.
  256.  
  257. 1.7 Delivery Registration
  258.  
  259. A simple form of delivery registration is supported by FTL0.  In the final 
  260. handshake after receiving a file, the client can command the server to modify 
  261. the contents of the PACSAT File Header to show the AX.25 address of the client 
  262. and the time at which the download was completed.  It is intended that this 
  263. facility be used if the file is specifically addressed to the client station, 
  264. not for files of general interest.  If the file has multiple destinations, one 
  265. ``registration'' is supported for each destination.  See Appendix A for fur-
  266. ther information.
  267.  
  268. 1.8 State Variables
  269.  
  270. In order to support full-duplex operations, the server and the client maintain 
  271. 2 state variables, one relating to the uploading of files and the other relat-
  272. ing to all other operations (selecting, directories, and downloading).  These 
  273. are called the uplink state and the downlink state variables.  
  274.  
  275. Appendix B provides pseudo-code definitions of the state transitions for 
  276. servers, Appendix C is for clients.
  277.  
  278.  
  279. 2.0 PACKET FORMAT
  280. An FTL0 packet is a sequence of information bytes preceded by a two byte 
  281. header.  After establishment of a data link, the first byte delivered to 
  282. either client or server is the first byte of a packet header.  The packet 
  283. header informs the client/server the type of the packet and the number of 
  284. information bytes which will follow.  There may be between 0 and 2047 informa-
  285. tion bytes, inclusive.  After reception of the final information byte of a 
  286. packet, the client/server expects the next byte to be the first byte of anoth-
  287. er packet header.  Such a stream is shown below, where [<info>] indicates that 
  288. there may be no data bytes.
  289.  
  290. <length_lsb><h1>[<info>...]<length_lsb><h1>[<info>...]
  291. |----First FTL0 packet-----|----Second FTL0 packet---|
  292.  
  293. 2.1 Header Format
  294. struct FTL0_PKT {
  295.      unsigned char length_lsb;
  296.      unsigned char h1;
  297. }
  298.  
  299. <length_lsb>  - 8 bit unsigned integer supplying the least significant 8  bits 
  300. of data_length.
  301.  
  302. <h1> - an 8-bit field.
  303.      bits 7-5 contribute 3 most significant bits to data_length.
  304.  
  305.      bits 4-0 encode 32 packet types as follows:
  306.  
  307.      0    DATA
  308.      1    DATA_END
  309.      2    LOGIN_RESP
  310.      3    UPLOAD_CMD
  311.      4    UL_GO_RESP
  312.      5    UL_ERROR_RESP
  313.      6    UL_ACK_RESP
  314.      7    UL_NAK_RESP
  315.      8    DOWNLOAD_CMD
  316.      9    DL_ERROR_RESP
  317.      10   DL_ABORTED_RESP
  318.      11   DL_COMPLETED_RESP
  319.      12   DL_ACK_CMD
  320.      13   DL_NAK_CMD
  321.      14   DIR_SHORT_CMD
  322.      15   DIR_LONG_CMD
  323.      16   SELECT_CMD
  324.      17   SELECT_RESP
  325.           All other values reserved
  326.  
  327.  
  328. 2.2 Information Length
  329.  
  330. The <information_length> value is formed by pre-pending bits 7-5 of the <h1> 
  331. byte to the <length_lsb> byte.  <information_length> indicates how many more 
  332. bytes will be received before the beginning of the next packet.  If <informa-
  333. tion_length> is 0, there are no information bytes.
  334.  
  335.  
  336. 3.0 LOGON
  337.  
  338. As soon as a data link is established between the client and the server, the 
  339. client is considered to be logged on.  The server sends a LOGIN_RESP packet 
  340. with one byte of flags and a 4-byte timestamp.  
  341.  
  342. When the client receives the LOGIN_RESP packet the server is initialized and 
  343. ready to begin transactions.
  344.  
  345. 3.1 Initiation of Session
  346.  
  347. An FTL0 session is initiated when a data link is established between the 
  348. client and the server.  
  349.  
  350. 3.2 Server Login Response Packet
  351.  
  352. When the data link is established the server transmits a LOGIN_RESP packet.
  353.  
  354. Packet: LOGIN_RESP
  355. Information: 5 bytes
  356. struct LOGIN_DATA{
  357.      unsigned long login_time;
  358.      unsigned char login_flags;
  359. }
  360.  
  361. <login_time>  -  a 32-bit unsigned integer indicating the  number  of  seconds 
  362. since January 1, 1970.
  363.  
  364. <login_flags> - an 8-bit field.
  365.      bit:76543210
  366.          xxxxSHVV
  367.  
  368. Bit 3, the SelectionActive bit, will be 1 if there is already an active selec-
  369. tion list for this client.  The SelectionActive bit will be 0 if there is no 
  370. active selection for this client already available.
  371.  
  372. Bit 2, the HeaderPFH bit, will be 1 if the server uses and requires PACSAT 
  373. File Headers on all files.  If the HeaderPFH bit is 1, the flag PFHserver used 
  374. in the following definition should be considered TRUE.
  375.  
  376. The HeaderPFH bit will be 0 if the server does not use PACSAT File Headers.  
  377. If the HeaderPFH bit is 0, the modified procedures specified in Section 7 
  378. should be used.
  379.  
  380. Bits 1 and 0 form a 2-bit FTL0 protocol version number.  The version described 
  381. here is 0.
  382.  
  383. 3.3 Server Login Initialization
  384.  
  385. Upon transmitting the LOGIN_RESP packet the server should initialize its state 
  386. variables to UL_CMD_WAIT and DL_CMD_WAIT.
  387.  
  388. 3.4 Client Login Initialization
  389.  
  390. Upon receiving the LOGIN_RESP packet, the client should initialize its state 
  391. variables to UL_CMD_OK and DL_CMD_OK.
  392.  
  393.  
  394. 4.0 SELECT
  395.  
  396. The select command is the mechanism through which the client can search the 
  397. server for desirable files.  The human user can search the files on the server 
  398. based on any information contained in the PACSAT File Header.  To achieve this 
  399. goal, the implementation and specification go through several levels of ab-
  400. straction which must be followed closely.
  401.  
  402. The user's desires form an equation.  The equation might simply be ``the file 
  403. is to G0K8KA and it was stored after my last logon''.  Or it might be more 
  404. complex, e.g. ``the file is less than 8 kbytes, and it was created after 9 
  405. July 1990, and it has ``landrover'' as one of its keywords''.  Humans would 
  406. naturally express this in ``infix'' notation:
  407.  
  408. (FILE_SIZE < 8k) && (CREATE_DATE > 9 July 1990) && (KEYWORDS == "*landrover*")
  409.  
  410. The server uses ``postfix'' notation, like an RPN calculator, and wants an 
  411. equation like:
  412.  
  413. (FILE_SIZE < 8k) (CREATE_DATE > 9 july 1990) && (KEYWORDS == "*landrover*") &&
  414.  
  415. To convert a postfix logical equation into a SELECT command, the client must 
  416. encode the logical operators, the relational operators the header item names, 
  417. and the values to compare against.  The header item names and comparison 
  418. values are encoded just as they are in the PACSAT File Header definition.  The 
  419. logical operators and relational operators are encoded as single bytes.  The 
  420. complete syntax is defined below.
  421.  
  422. 4.1 Client Issuing Select Command
  423.  
  424. When the client's downlink state variable is DL_CMD_OK (e.g. the client is not 
  425. involved in another select, file download, or directory download), the client 
  426. may transmit a SELECT_CMD packet.
  427.  
  428. Packet: SELECT_CMD
  429. Information: variable length 
  430. SELECTION
  431. SELECTION is defined recursively by the following structures and rules.
  432. struct SELECTION {
  433.      struct LVALUEx equation;
  434.      unsigned char end_flag;
  435. }
  436.  
  437. <end_flag> - 0x00
  438. <equation> is recursively defined by 
  439. two structures LVALUE0 and LVALUE1:
  440. struct LVALUE0 {
  441.      struct LVALUEx t1;
  442.      struct LVALUEx t2;
  443.      unsigned char lop;
  444. }
  445.  
  446. <t1> and <t2> are further LVALUE0 or LVALUE1 structures.
  447. <lop> is and 8-bit field representing a logical operator:
  448.           bit 76543210
  449.               00000001     is AND
  450.               00000010     is OR
  451.  
  452. struct LVALUE1 {
  453.      unsigned char relop;
  454.      unsigned int item_id;
  455.      unsigned char length;
  456.      unsigned char constant[];
  457. }
  458.  
  459. <relop> is an 8-bit field encoding a relational operator:
  460.   bit7
  461.      0
  462.  
  463.   bit654  Relational Operator
  464.      000  equal to
  465.      001  greater than
  466.      010  less than
  467.      011  not equal
  468.      100  greater than or equal to
  469.      101  less than or equal to
  470.      110  reserved
  471.      111  reserved
  472.  
  473.   bit3210 Type of Comparison
  474.                0000 treat <constant> as a 
  475.                     multi-byte unsigned 
  476.                     integer (valid for 
  477.                     <length> 1,2, and 4).
  478.                0001 treat <constant> as a 
  479.                     multi-byte signed 
  480.                     integer (valid for 
  481.                     <length> 1,2,and 4).
  482.                0010 treat <constant> as an 
  483.                     array                of 
  484.                     unsigned char
  485.                0011 treat <constant> as an 
  486.                     array of ASCII 
  487.                     characters, convert to 
  488.                     lower case before making 
  489.                     comparison.
  490.                0100 treat <constant> as an 
  491.                     array of ASCII 
  492.                     characters, convert to 
  493.                     lower case before 
  494.                     comparison and interpret 
  495.                     wildcard characters.
  496.                ALL OTHER VALUES RESERVED.
  497.  
  498. <item_id> is a 16-bit unsigned integer identifying one of the PACSAT Header 
  499. Definition header items.
  500.  
  501. <length> is the number of bytes in the <constant[ ]> array.
  502.  
  503. <constant[ ]> is an array of bytes which are compared against the header item 
  504. identified by <item_id>, using the specified relational operator and compari-
  505. son type.
  506.  
  507. 4.2 Response to Select Command
  508.  
  509. The server responds with one of the packets from 4.2.1 or 4.2.2 and returns 
  510. its downlink state to DL_CMD_OK, ready to accept another command from the 
  511. client.
  512.  
  513. 4.2.1 Successful Selection
  514.  
  515. If the server can interpret the SELECT_CMD packet, it responds with a 
  516. SELECT_RESP packet
  517.  
  518. Packet: SELECT_RESP
  519. Information: 2 bytes
  520.                     unsigned int no_of_files
  521.  
  522. <no_of_files> is a 16 bit unsigned integer telling how many files have been 
  523. selected.  It may be 0.
  524.  
  525. 4.2.2 Unsuccessful Selection
  526.  
  527. If the server cannot interpret the SELECT_CMD packet, it responds with a 
  528. DL_ERROR_RESP packet.
  529.  
  530. Packet: DL_ERROR_RESP
  531. Information: 1 byte
  532.                     unsigned char err_code
  533.  
  534. <err_code> is ER_POORLY_FORMED_SEL if the selection equation could not be 
  535. parsed by the server because of a syntax error.
  536.  
  537.  
  538. 5.0 DOWNLOAD
  539. To receive a file from the server, the client uses the download command.  This 
  540. command can be used to download a specific file, to continue the downloading 
  541. of a specific file, or to download the next file in the selection list.
  542.  
  543. 5.1 Client Initiates Download
  544.  
  545. When the client's uplink state variable is DL_CMD_OK, the client may send the 
  546. DOWNLOAD_CMD packet.
  547.  
  548. Packet: DOWNLOAD_CMD
  549. Information : 9 bytes of arguments with the following structure
  550.  
  551. struct {
  552.      unsigned long file_no;
  553.      unsigned long byte_offset;
  554.      unsigned char lock_destination;
  555. }
  556.  
  557. <file_no> is a 32-bit binary integer uniquely identifying a file on the serv-
  558. er.  Two reserved values have special meanings: If <file_no> is equal to 
  559. 0xffffffff, the server will attempt to use the next file in the current selec-
  560. tion list, moving from older files to newer files.  If <file_no> is equal to 
  561. 0, the server will attempt to use the next file in the current selection list, 
  562. moving from newer files toward older files.  If <file_no> is not one of the 
  563. reserved values, the server attempts to download the file which it associates 
  564. with <file_no>.
  565.  
  566. <byte_offset> is a 32-bit unsigned binary integer giving the offset from the 
  567. beginning of the file at which the download should begin.  If the client is 
  568. continuing an aborted download, this argument should be set to the number of 
  569. bytes previously received.  Otherwise it should be 0.  
  570.  
  571. <lock_destination> is an 8 bit unsigned binary integer.  It will generally be 
  572. set to 0 by non-gateway stations.  
  573.  
  574. [If <lock_destination> is not 0, it indicates that the client wishes to con-
  575. duct a locked download for the destination numbered by <lock_destination>.  If 
  576. the <lock_destination> exists and is not already locked, the client's AX.25 
  577. address is placed in the PACSAT File Header AX25_DOWNLOADER item associated 
  578. with the specified DESTINATION item.  Destination numbering is defined in 
  579. section Appendix A.]
  580.  
  581. 5.2 Server Responses to the Download Command
  582.  
  583. When it receives a DOWNLOAD_CMD packet the server determines whether the 
  584. download is possible.  This may include determination of the desired file 
  585. number from the current select list.
  586.  
  587. 5.2.1  Downlinking File Data
  588.  
  589. If the download is possible the server transmits the file data beginning 
  590. <byte_offset> bytes from the beginning of the file.  If <byte_offset> is 
  591. greater than or equal to the file length, no data is transmitted.  The file 
  592. data bytes are transmitted as information in DATA packets.  These packets may 
  593. be any size from 0 to 2047 bytes.
  594.  
  595. [If <lock_destination> is not-zero, the server sets the <DOWNLOAD_TIME> asso-
  596. ciated <lock_destination> before beginning to send DATA packets.]
  597.  
  598. Once the server has transmitted a DATA packet containing the last byte of the 
  599. file, or if the <byte_offset> was greater than or equal to the file length, 
  600. the server transmits a single DATA_END packet.  After transmitting the end 
  601. packet, the server expects to receive a DL_ACK_CMD or DL_NAK_CMD.
  602.  
  603. 5.2.2 Failure of Download Command
  604.  
  605. If the server cannot service the download command, it responds with a 
  606. DL_ERROR_RESP packet.
  607.  
  608. Packet: DL_ERROR_RESP
  609. Information: 1 byte
  610.      unsigned char err_code;
  611.  
  612. <err_code> is an 8-bit unsigned binary integer will be one of:
  613.  
  614. ER_SELECTION_EMPTY if the selection list has no more files in it or no select 
  615. command was previously received.
  616.  
  617. ER_NO_SUCH_FILE_NUMBER if the file identified by <file_no> does not exist.
  618.  
  619. [ER_ALREADY_LOCKED - <lock_destination> was not 0, and the file is already 
  620. locked for the specified destination.
  621.  
  622. ER_NO_SUCH_DESTINATION - <lock_destination> was not 0, and the file has fewer 
  623. than <lock_destination> DESTINATION items in its PACSAT File Header.]
  624.  
  625. 5.3 Client Accepting or Rejecting Downloaded File
  626.  
  627. 5.3.1 Successful Download
  628. Upon reception of the DATA_END packet from the server, the client performs any 
  629. possible checks on the received file.  If the file passes the checks, the 
  630. client transmits a DL_ACK_CMD packet.
  631.  
  632. Packet: DL_ACK_CMD
  633. Information: 1 byte
  634.                     unsigned char <register_destination>
  635.  
  636. <register_destination> is an 8-bit unsigned integer identifying one of the 
  637. destinations in the PACSAT File Header of the downloaded file. 
  638. <register_destination> should be 0 if the client does not wish to register 
  639. receipt of the file.
  640.  
  641. Upon receiving the DL_ACK_CMD packet, the server completes the download proc-
  642. ess.  
  643.  
  644. [If <register_destination> is not 0, the appropriate DESTINATION item in the 
  645. PACSAT File Header is located and the associated AX25_DOWNLOADER and 
  646. DOWNLOAD_TIME items are updated.  
  647.  
  648. If <lock_destination> was non-zero in the DOWNLOAD_COMMAND, the server locates 
  649. the appropriate DESTINATION item in the PACSAT File Header and updates the 
  650. associated DOWNLOAD_TIME item.]
  651.  
  652. 5.3.2 Unsuccessful or Aborted Download 
  653.  
  654. If the client wishes to abort the download before receiving the DATA_END 
  655. packet from the server, or finds that the downloaded file fails some integrity 
  656. test after reception of the DATA_END packet, the client sends the DL_NAK_CMD 
  657. packet.
  658.  
  659. Packet: DL_NAK_CMD
  660. Information: none
  661.  
  662. Upon receiving this packet, if the server has not already sent the DATA_END 
  663. packet, it will do so and proceed to the final unsuccessful download handshake 
  664. (5.4.2).  If DL_NAK_CMD is received after the server has transmitted the 
  665. DATA_END packet, the server proceeds to the final download handshake.
  666.  
  667. 5.4 Final Download Handshake
  668.  
  669. 5.4.1 Completion of Successful Download
  670.  
  671. [If the server receives the DL_ACK_CMD, it removes any <lock_destination> lock 
  672. from the file and sets <AX25_DOWNLOADER> and <DOWNLOAD_TIME> for the specified 
  673. <DESTINATION> item.]
  674.  
  675. [If <register_destination> in the DL_ACK_CMD is non-zero, the server attempts 
  676. to set the <AX25_DOWNLOADER> and <DOWNLOAD_TIME> items associated with the 
  677. specified <DESTINATION> item.  If the <register_destination> does not exist, 
  678. the server transmits a DL_ABORTED_RESP packet.]
  679.  
  680. If <register_destination> was 0, the server transmits a DL_COMPLETED_RESP 
  681. packet, and returns its downlink state variable to DL_CMD_OK.
  682.  
  683. Packet: DL_COMPLETED_RESP
  684. Information: none.
  685.  
  686. This response tells the client that the server has completed processing the 
  687. DL_ACK_CMD.  The client downlink state variable should be set to DL_CMD_OK.
  688.  
  689. If the L2 link fails before the client receives the DL_DONE_RESP, the client 
  690. cannot be sure the DL_ACK_CMD was processed.  This is important if the client 
  691. had specified a <lock_destination> or a <register_destination>.  In either of 
  692. these cases, the client should treat the download as incomplete and continue 
  693. it later.  This assures that the PACSAT File Header has been properly modi-
  694. fied.  If both <lock_destination> and <register_destination> were 0, the 
  695. client can consider the download complete.
  696.  
  697. 5.4.2 Completion of Unsuccessful Download
  698.  
  699. A download is ``unsuccessful'' if the server receives the DL_NAK_CMD from the 
  700. client or if <register_destination> is non-zero and indicates a non-existent 
  701. destination.  
  702.  
  703. If <lock_destination> was non-zero, the lock is removed and <DOWNLOAD_TIME> is 
  704. updated.
  705.  
  706. The server transmits the DL_ABORTED_RESP packet.  
  707.  
  708. Packet: DL_ABORTED_RESP
  709. Information: none
  710.  
  711. The server downlink state variable returns to the DL_CMD_OK state.
  712. Upon reception of the DL_ABORTED_RESP the client downlink state variable 
  713. returns to DL_CMD_OK.  
  714.  
  715.  
  716. 6.0 DIRECTORY
  717.  
  718. The client uses directory commands to get information about files on the 
  719. server.  Servers conforming to the PACSAT File Header Definition send PACSAT 
  720. File Headers as directory entries.  ``Long'' directory entries are the com-
  721. plete PACSAT File Header and ``short'' directory entries are only the Mandato-
  722. ry File Header items.
  723.  
  724. The client can request a directory entry for a specific file or for the files 
  725. in the selection list.  The selection list can be scanned from oldest to 
  726. newest files or from newest to oldest files.
  727.  
  728. 6.1 Initiating a Directory 
  729.  
  730. The client may request a directory whenever the client downlink state variable 
  731. is DL_CMD_OK.  To request a directory, the client transmits either a 
  732. DIR_LONG_CMD packet or a DIR_SHORT_CMD packet.
  733.  
  734. Packet: DIR_LONG_CMD
  735.        or DIR_SHORT_CMD
  736. Information: 4 bytes
  737.      unsigned long file_no;
  738.  
  739. <file_no> is a 32-bit unsigned binary integer identifying a file or files on 
  740. the server.  There are two reserved values: 0 and 0xffffffff.  If <file_no> is 
  741. 0xffffffff, the server will send directory entries for the next 10 files in 
  742. the current selection list, moving from older files to newer files.  If 
  743. <file_no> is 0, the server will send directory entries for the next 10 files 
  744. in the current selection list, moving from newer files toward older files.
  745.  
  746. 6.2  Server Responses to Directory Commands
  747.  
  748. 6.2.1 Successful Directory Request
  749.  
  750. If the directory request can be serviced (there are files in the selection 
  751. list, or a specified file exists) the server will transmit one or more PACSAT 
  752. File Headers in a series of DATA packets followed by a DATA_END packet.  A 
  753. maximum of 10 file headers will be transmitted for each DIR command.
  754.  
  755. 6.2.2. Failed Directory Request
  756.  
  757. If the directory request cannot be serviced, a DL_ERROR_RESP packet is trans-
  758. mitted.
  759.  
  760. Packet: DL_ERROR_RESP
  761. Information: 1 byte
  762.                     unsigned char err_code;
  763.  
  764. <err_code> will be one of:
  765. ER_SELECTION_EMPTY - if the <file_no> was 0 or 0xffffffff, and either there 
  766. are no files left in the selection list or there is no selection list.
  767.  
  768. ER_NO_SUCH_FILE_NUMBER - if <file_no> is not 0 or 0xffffffff and no file 
  769. identified by <file_no> exists on the server.
  770.  
  771.  
  772. 7. UPLOAD
  773. 7.1. Initiating an Upload
  774.  
  775. The client can initiate an upload any time the client's upload state variable 
  776. is UL_CMD_OK.
  777.  
  778. Packet: UPLOAD_CMD
  779. Information: 8 bytes
  780. struct {
  781.      unsigned long continue_file_no;
  782.      unsigned long file_length;
  783. }
  784.  
  785. <continue_file_no> - a 32-bit unsigned integer identifying the file to contin-
  786. ue.   Used to continue a previously-aborted upload.  Must be 0 when commencing 
  787. a new upload.
  788.  
  789. <file_length> -  32-bit unsigned integer indicating the number of bytes in the 
  790. file.
  791.  
  792. 7.2 Server Responses to Upload requests
  793.  
  794. Downlink Packet: UL_GO_RESP or UL_ERROR_RESP
  795.  
  796. 7.2.1 Successful Upload Request
  797.  
  798. Packet: UL_GO_RESP
  799. Information: 8 bytes
  800. struct {
  801.      unsigned long server_file_no;
  802.      unsigned long byte_offset;
  803. }
  804.  
  805. <server_file_no> is a 32-bit unsigned binary integer identifying the client's 
  806. file on the server.
  807.  
  808. <byte_offset> is a 32-bit unsigned binary integer number of bytes from the 
  809. beginning of the file at which the client should begin file transmission. This 
  810. will be 0 if the <continue_file_no> was zero.
  811.  
  812. After receiving the UPLOAD_PROCEED_RESP packet, the client should advance to 
  813. the data transmitting state described in Section 7.3.  
  814.  
  815. 7.2.2 Unsuccessful Upload Request
  816. If the server cannot process the upload request, it will transmit an 
  817. UL_ERROR_RESP packet.
  818.  
  819. Packet: UL_ERROR_RESP
  820. Information: 1 byte
  821.      unsigned char err_code;
  822.  
  823. <err_code> must be one of:
  824. ER_NO_SUCH_FILE_NUMBER if <continue_file_no> is not 0 and the file identified 
  825. by <continue_file_no> does not exist.  Continue is not possible.
  826.  
  827. ER_BAD_CONTINUE if <continue_file_no> is not 0 and the <file_length> does not 
  828. agree with the <file_length> previously associated with the file identified by 
  829. <continue_file_no>.  Continue is not possible.
  830.  
  831. ER_FILE_COMPLETE if <continue_file_no> is not 0 and the file identified by 
  832. <continue_file_no> was completely received on a previous upload.  Note - 
  833. receipt of this command should be accepted by the client as confirmation of 
  834. file receipt by the server.
  835.  
  836. ER_NO_ROOM if the server does not have room for the file.
  837.  
  838. After transmitting the UL_ERROR_RESP packet, the server's uplink state varia-
  839. ble is set to UL_CMD_OK.
  840.  
  841. 7.2.3  Continuation of Uploads
  842.  
  843. Any file for which the client receives a UL_GO_RESP should be continued until 
  844. a UL_ACK_RESP or a non-recoverable UL_ERR_RESP or UL_NAK_RESP for that file is 
  845. received.  The server should be prepared to continue reception of any file for 
  846. which it has transmitted a UL_GO_RESP.  Some file numbers will be allocated by 
  847. the server and lost by link failure before the UL_GO_RESP reaches the client; 
  848. a 32-bit file number space provides sufficient scope for some lost file num-
  849. bers.  To avoid saving partial files for these lost file numbers, the server 
  850. should not reserve space for a message until it has received at least one DATA 
  851. packet from the client.
  852.  
  853. 7.3. Data Uplinking Stage
  854.  
  855. The client now uplinks the bytes from the file, in DATA packets.  The uplink-
  856. ing should begin <byte_offset> bytes from the start of the file.  After trans-
  857. mitting a DATA packet containing the last byte in the file, the client should 
  858. transmit a DATA_END packet.  The client should also transmit a DATA_END packet 
  859. if the <byte_offset> was greater than or equal to the file length.
  860.  
  861. The server may attempt to terminate the upload by transmitting a UL_NAK_RESP 
  862. at any time during the upload.  If the client receives a UL_NAK_RESP packet 
  863. before transmitting a DATA_END packet the client must send a DATA_END packet.
  864.  
  865. 7.4. Completion of Upload
  866.  
  867. 7.4.1 Successful Upload Completion 
  868.  
  869. When the server receives the DATA_END packet it will check the integrity of 
  870. the file as far as possible.  If the checks pass, the server will downlink a 
  871. UL_ACK_RESP packet.  
  872.  
  873. Packet: UL_ACK_RESP
  874. Information: none
  875.  
  876. After transmitting the UL_ACK_RESP the server uplink state variable is 
  877. UL_CMD_OK.  After receiving the UL_ACK_RESP, the client uplink state variable 
  878. is UL_CMD_OK.
  879.  
  880. 7.4.2 Failure Caused by Server Rejecting Upload
  881.  
  882. The server may reject an upload while the client is sending DATA packets (due 
  883. to file system problems on the server) or after the client has sent the 
  884. DATA_END packet (due to corruption of the file).  
  885.  
  886. If the server must abort the upload while receiving DATA packets or after 
  887. receiving the DATA_END checks fail, it sends the UL_NAK_RESP packet.  
  888.  
  889. Information: 1 byte
  890.      unsigned char err_code;
  891. <err_code>     must be one of:
  892.  
  893. ER_BAD_HEADER - The file either has no PFH, or has a badly-formed PFH.
  894. ER_HEADER_CHECK - The PFH checksum failed.
  895. ER_BODY_CHECK - The PFH body checksum failed.  
  896. ER_NO_ROOM - The server ran out of room for file storage before the upload was 
  897. complete.  The server will implement procedures to avoid frequently running 
  898. out of room, but this cannot be guaranteed.
  899.  
  900. After transmitting the UL_NAK_RESP packet, the server uplink state variable is 
  901. UL_CMD_OK.  After receiving the UL_ERROR_RESP, the client uplink state varia-
  902. ble is UL_CMD_OK.
  903.  
  904. 7.4.3 Link Failure During Upload
  905.  
  906. If the data link fails before the server receives the DATA_END packet, the 
  907. server retains the offset of the next byte needed for the file.  This value 
  908. will be transmitted by the server as <byte_offset> if the client later contin-
  909. ues the upload by specifying the <server_file_no> in the <continue_file_no> of 
  910. an UPLOAD_CMD packet.  If the offset is not 0, the server may safely retain a 
  911. temporary file containing the data received so far.  If the server retains 
  912. files for which the <byte_offset> is 0, these should be purged after some 
  913. reasonable time, since the client may not know the <server_file_no> of the 
  914. file.
  915.  
  916.  
  917. 8.0 TERMINATION OF SESSION 
  918.  
  919. The session is terminated by closing the data link.  Either the client or the 
  920. server may decide to close the link when uplink state is UL_CMD_OK and down-
  921. link state is DL_CMD_OK.  The link is also terminated if unexpected packets 
  922. are received.  
  923.  
  924. If the link terminates when any state machine is not in the _CMD_OK state, 
  925. appropriate actions are taken.
  926.  
  927.  
  928. 9.0 OTHER ERROR CONDITIONS
  929.  
  930. There are other error conditions which might occur when a server is processing 
  931. commands.  Such errors are indicated by DL_ERROR_RESP or UL_ERROR_RESP packets 
  932. with appropriate error codes.  Robust client implementations will be prepared 
  933. to handle such packets at any time during the session.
  934.  
  935. Specific codes which have currently been assigned are ER_ILL_FORMED_CMD and 
  936. ER_SERVER_FSYS.
  937.  
  938. 9.1 ER_ILL_FORMED_CMD
  939.  
  940. This error code is transmitted by the client when a command is received with 
  941. too many or too few data bytes, and when an unrecognized command is received. 
  942. The current command is aborted and the appropriate server state machine is 
  943. returned to the _CMD_OK state.
  944.  
  945. 9.2 ER_SERVER_FSYS
  946.  
  947. This indicates a failure in the server file system, e.g. no file handles 
  948. available for the server to complete the requested operation.  The current 
  949. command is aborted, and the appropriate server state machine is returned to 
  950. the _CMD_OK state."
  951.  
  952.  
  953.  
  954.  
  955. APPENDIX A - Use of the PACSAT File Header
  956.  
  957. The PACSAT File Header Definition defines a standard header which will be 
  958. found at the beginning of every file downloaded from PACSAT (or any fully 
  959. compliant FTL0 server).   
  960.  
  961. One purpose of the PACSAT File Header is to allow clients to determine the 
  962. status of files on the server.  Specifically, the originating client may wish 
  963. to find out if the file has been downloaded by its intended destination, and a 
  964. Gateway client may wish to find out if a message still needs to be downloaded 
  965. for relay to a particular destination.  Both of these tasks are done by exam-
  966. ining a set of PACSAT File Header Items comprising <DESTINATION>, <AX25_DOWN-
  967. LOADER> and <DOWNLOAD_TIME>.
  968.  
  969. A gateway will examine <DESTINATION> to see if it can relay or deliver the 
  970. file.  If so, it will examine <DOWNLOAD_TIME> and <AX25_DOWNLOADER> to deter-
  971. mine the delivery status of the message:
  972.  
  973. If <DOWNLOAD_TIME> is zero, the message still needs to be relayed.
  974.  
  975. If <DOWNLOAD_TIME> is non-zero, but <AX25_DOWNLOADER> is blanks, the message 
  976. is in the process of being downloaded, and the download started at 
  977. <DOWNLOAD_TIME>.
  978.  
  979. If <DOWNLOAD_TIME> is non-zero, and <AX25_DOWNLOADER> is non-blank, the mes-
  980. sage has been downloaded for relay to the <DESTINATION>.
  981.  
  982. A similar (but simpler) procedure is used to see if a specific destination 
  983. station has ``registered receipt'' of a file.  When receipt is registered (at  
  984. the end of a successful download), <AX25_DOWNLOADER> and <DOWNLOAD_TIME> will 
  985. both be correctly set.
  986.  
  987. For these checks to work correctly, the downloading clients must use the 
  988. proper command procedures.  Gateways must set the correct <lock_destination> 
  989. in their DOWNLOAD_CMD packets, and clients must set the correct 
  990. <register_destination> in the DL_ACK_CMD.  The <lock_destination> procedure 
  991. should be implemented by all gateways. The <register_destination> procedure is 
  992. optional for client implementations.
  993.  
  994. The proper number for <register_destination> or <lock_destination> is deter-
  995. mined as follows.  If a file has only one <DESTINATION> item, it is destina-
  996. tion 1.  Any other destinations are numbered sequentially in order of occur-
  997. rence in the PACSAT File Header.
  998.  
  999.  
  1000. APPENDIX B - Server State Transition Definitions
  1001.  
  1002. SERVER STATE DEFINITIONS
  1003.  
  1004. The following pseudo code defines the transitions of the Server state machines 
  1005. in FTL0.  One state machine is used for file uploading.  The other state 
  1006. machine is used for all other procedures.
  1007.  
  1008. It is assumed that the data link will be terminated if there have been no 
  1009. packets transmitted or received for a period of time (TBD).  If the link is 
  1010. terminated by this ``activity timeout'' both state machines receive a ``Data 
  1011. Link Terminated'' event.  ``Data Link Terminated'' is also generated if the 
  1012. link fails for any reason.
  1013.  
  1014. When an unexpected packet is received by one of the state machines, that state 
  1015. machine terminates the data link and returns to an uninitialized state.  The 
  1016. second state machine is notified of this through a ``Data Link Terminated'' 
  1017. event, and also returns to an uninitialized state.  At this point, the FTL0 
  1018. processing for this client ceases until the establishment of another data 
  1019. link.
  1020.  
  1021. STARTUP
  1022.  
  1023.           State variables are created when a data link is established between client and 
  1024.           server.  The server executes the following:
  1025.                Transmit LOGIN_RESP packet.
  1026.                ul_state := UL_CMD_OK
  1027.                dl_state := DL_CMD_OK 
  1028.  
  1029.  
  1030.           SERVER UPLINK STATE MACHINE 
  1031.           This machine receives only frames which are relevant to the file uploading 
  1032.           process : UPLOAD_CMD, DATA, and DATA_END.  It also is executed upon timeout of 
  1033.           the input timer or termination of the level 2 link (from local or remote 
  1034.           causes).
  1035.           state UL_CMD_OK {
  1036.  
  1037.                EVENT: Receive UPLOAD_CMD packet{
  1038.                     if ok to upload
  1039.                          Send UPLOAD_GO_RESP packet.
  1040.                          ul_state <- UL_DATA_RX
  1041.                     else
  1042.                          Send UL_ERROR_RESP packet.
  1043.                          ul_state <- UL_CMD_OK
  1044.                }
  1045.  
  1046.                EVENT: DEFAULT{
  1047.                     if EVENT is not "data link terminated"
  1048.                           Terminate data link.
  1049.                     ul_state <- UL_UNINIT
  1050.                }
  1051.           }
  1052.  
  1053.           state UL_DATA_RX {
  1054.  
  1055.                EVENT: Receive DATA packet {
  1056.                     Try to store data.
  1057.                     if out of storage {
  1058.                          Transmit UL_NAK_RESP packet.
  1059.                          Close file.
  1060.                          Save file_offset and file_number.
  1061.                          ul_state <- UL_ABORT
  1062.                     }
  1063.                     else {
  1064.                          Update file_offset.
  1065.                          ul_state <- UL_DATA_RX
  1066.                     }
  1067.                }
  1068.  
  1069.                EVENT: Receive DATA_END packet {
  1070.                     Close file.
  1071.                     if file passes checks {
  1072.                          Transmit UL_ACK_RESP packet
  1073.                          ul_state <- UL_CMD_OK
  1074.                     }
  1075.                     else {
  1076.                          file_offset <- 0
  1077.                          Save file_offset and file_number
  1078.                          Transmit UL_NAK_RESP packet
  1079.                          ul_state <- UL_CMD_OK
  1080.                     }
  1081.                }
  1082.  
  1083.                EVENT: DEFAULT{
  1084.                     if (file_offset > 0)
  1085.                          Save file_offset and file number.
  1086.                     if EVENT is not "data link terminated"
  1087.                           Terminate data link.
  1088.                     ul_state <- UL_UNINIT
  1089.                }
  1090.           }
  1091.  
  1092.           state UL_ABORT {
  1093.  
  1094.                EVENT: Receive DATA packet 
  1095.                     ul_state <- UL_ABORT
  1096.  
  1097.                EVENT: Receive DATA_END packet 
  1098.                     ul_state <- UL_CMD_OK
  1099.  
  1100.                EVENT: DEFAULT{
  1101.                     if EVENT is not "data link terminated"
  1102.                           Terminate data link.
  1103.                     ul_state <- UL_UNINIT
  1104.                }
  1105.           }
  1106.  
  1107.  
  1108.           SERVER DOWNLINK STATE MACHINE 
  1109.  
  1110.           This machine receives all packets other than UPLOAD_CMD, DATA, and DATA_END.  
  1111.           state DL_CMD_OK {
  1112.  
  1113.                EVENT: Receive SELECT_CMD packet {
  1114.                     if syntax is correct {
  1115.                          Form select list.
  1116.                          Transmit SELECT_RESP packet.
  1117.                          dl_state <- DL_CMD_OK
  1118.                     }
  1119.                     else {
  1120.                          Transmit DL_ERROR_RESP packet.
  1121.                          dl_state <- DL_CMD_OK
  1122.                     }
  1123.                }
  1124.  
  1125.                EVENT: Receive DIR_LONG_CMD or DIR_SHORT_CMD packet {
  1126.                     if there are directories to send 
  1127.                          dl_state <- DL_DIR_DATA
  1128.                     else {
  1129.                          Transmit DL_ERROR_RESP packet.
  1130.                          dl_state <- DL_CMD_OK
  1131.                     }
  1132.                }
  1133.  
  1134.                EVENT: Receive DOWNLOAD_CMD packet {
  1135.                     if request can be serviced  {
  1136.                             seek to <offset>
  1137.                          if <lock_destination> <> 0 
  1138.                               set PFH DOWNLOAD_TIME.
  1139.                          dl_state <- DL_FILE_DATA
  1140.                     }
  1141.                     else {
  1142.                          Transmit DL_ERROR_RESP packet.
  1143.                          dl_state <- DL_CMD_OK
  1144.                     }
  1145.                }
  1146.  
  1147.                EVENT: Receive DL_NAK_CMD packet 
  1148.                     dl_state <- DL_CMD_OK
  1149.  
  1150.                EVENT: DEFAULT{
  1151.                     if EVENT is not "data link terminated"
  1152.                           Terminate data link.
  1153.                     dl_state <- DL_UNINIT
  1154.                }
  1155.           }
  1156.  
  1157.           state DL_DIR_DATA {
  1158.                if there is more directory data to send {
  1159.                     Transmit directory data in DATA packets.
  1160.                     dl_state <- DL_DIR_DATA
  1161.                }
  1162.                else {
  1163.                     Transmit DATA_END packet.
  1164.                     dl_state <- DL_CMD_OK
  1165.                }
  1166.  
  1167.                EVENT: Receive DL_NAK_CMD packet{
  1168.                     Transmit DATA_END packet.
  1169.                     dl_state <- DL_CMD_OK.
  1170.                }
  1171.  
  1172.                EVENT: DEFAULT{
  1173.                     if EVENT is not "data link terminated"
  1174.                           Terminate data link.
  1175.                     dl_state <- DL_UNINIT
  1176.                }
  1177.           }
  1178.  
  1179.           state DL_FILE_DATA {
  1180.  
  1181.                if there is more file data to send
  1182.                     Transmit file data in DATA packets.
  1183.                     dl_state <- DL_FILE_DATA
  1184.                }
  1185.                else {
  1186.                     Transmit DATA_END packet.
  1187.                     dl_state <- DL_FILE_END
  1188.                }
  1189.  
  1190.                EVENT: Receive DL_NAK_CMD packet {
  1191.                     If lock_destination <> 0
  1192.                          unlock lock_destination.
  1193.                     Transmit DATA_END packet.
  1194.                     Transmit DL_ABORTED_RESP packet.
  1195.                     dl_state <- DL_CMD_OK
  1196.                }
  1197.  
  1198.                EVENT: DEFAULT {
  1199.                     If lock_destination <> 0
  1200.                          unlock lock_destination.
  1201.                     if EVENT is not "data link terminated"
  1202.                           Terminate data link.
  1203.                     dl_state <- DL_UNINIT
  1204.                }
  1205.           }
  1206.  
  1207.           state DL_FILE_END {
  1208.  
  1209.                EVENT: Receive DL_NAK_CMD packet {
  1210.                     dl_state <- DL_CMD_OK
  1211.                     Transmit DL_ABORTED_RESP packet.
  1212.                     If lock_destination <> 0
  1213.                          unlock lock_destination.
  1214.                }
  1215.  
  1216.                EVENT: Receive DL_ACK_CMD packet {
  1217.                     if register_destination <> 0 and register_destination exists {
  1218.                          set PFH AX25_DOWNLOADER
  1219.                          set PFH DOWNLOAD_TIME
  1220.                          Transmit DL_COMPLETED_RESP packet.
  1221.                     }
  1222.                     else if register_destination <> 0 and it doesn't exist {
  1223.                          Transmit DL_ABORTED_RESP.
  1224.                     }
  1225.                     else if lock_destination <> 0 {
  1226.                          unlock lock_destination.
  1227.                          set PFH AX25_DOWNLOADER.
  1228.                          set PFH DOWNLOAD_TIME.
  1229.                          Transmit DL_COMPLETED_RESP packet.
  1230.                     }
  1231.                     dl_state <- DL_CMD_OK
  1232.                }
  1233.  
  1234.                EVENT: DEFAULT {
  1235.                     If lock_destination <> 0
  1236.                          unlock lock_destination.
  1237.                     if EVENT is not "data link terminated"
  1238.                           Terminate data link.
  1239.                     dl_state <- DL_UNINIT
  1240.           }
  1241.  
  1242.  
  1243. APPENDIX C - Client State Transition Definitions
  1244.  
  1245. Client Pseudo-code State diagrammes.
  1246.  
  1247. The following diagrammes indicate how an FTL0 client should react to different 
  1248. events when in different states.  
  1249.  
  1250. ``User Requests'' come from the process using the FTL0 state machine.
  1251.  
  1252. Receive packets come from the data link and transmit packets go to the data 
  1253. link.
  1254.  
  1255. It is assumed that the data link will be terminated if there have been no 
  1256. packets transmitted or received for a period of time (TBD).  If the link is 
  1257. terminated by this ``activity timeout'' the state machines receive a ``Data 
  1258. Link Terminated'' event.  ``Data Link Terminated'' is also generated if the 
  1259. link fails for any reason.
  1260.  
  1261.           UPLINK STATE MACHINE
  1262.  
  1263. The client uplink state machine controls the file uploading process.  File 
  1264. downloading and all other processes are controlled by the downlink state 
  1265. machine.
  1266.  
  1267. The state of the uplink is indicated by the ul_state variable.
  1268.  
  1269. The uplink state machine processes the following events:
  1270.  
  1271.                EVENT: User Requests Uplink
  1272.                EVENT: Data Link Terminated
  1273.                EVENT: Receive UL_GO_RESP
  1274.                EVENT: Receive UL_ERROR_RESP
  1275.                EVENT: Receive UL_ACK_RESP
  1276.                EVENT: Receive UL_NAK_RESP
  1277.  
  1278. Where the ``EVENT: DEFAULT'' is indicated, this includes all events on the 
  1279. above list which have not already been processed.  
  1280.  
  1281.           State UL_UNINIT {
  1282.  
  1283.                EVENT: User Requests File Upload
  1284.                     Refuse.
  1285.  
  1286.                EVENT: DEFAULT
  1287.                     ignore.
  1288.           }
  1289.  
  1290.           State UL_CMD_OK {
  1291.  
  1292.                EVENT: User Requests File Upload {
  1293.                     Transmit UL_CMD packet, setting <continue_file_no> if necessary.
  1294.                     ul_state <- UL_WAIT
  1295.                }
  1296.  
  1297.                EVENT: DEFAULT{
  1298.                     if EVENT is not "data link terminated"
  1299.                           Terminate data link.
  1300.                     ul_state <- UL_UNINIT
  1301.                }
  1302.           }
  1303.  
  1304.           State UL_WAIT {
  1305.  
  1306.                EVENT: Receive UL_GO_RESP packet. {
  1307.                     Associate <server_file_number> with the file.
  1308.                     Mark the file CONTINUE.
  1309.                     ul_state <- UL_DATA
  1310.                }
  1311.  
  1312.                EVENT: Receive UL_ERROR_RESP packet. {
  1313.                     If error is unrecoverable, mark the file IMPOSSIBLE.
  1314.                     ul_state <- UL_CMD_OK
  1315.                }
  1316.  
  1317.                EVENT: DEFAULT{
  1318.                     if EVENT is not "data link terminated"
  1319.                           Terminate data link.
  1320.                     ul_state <- UL_UNINIT
  1321.                }
  1322.           }
  1323.  
  1324.           State UL_DATA {
  1325.                If there is data to send {
  1326.                     Transmit DATA packet.
  1327.                     ul_state <- UL_DATA.
  1328.                }
  1329.                else {
  1330.                     Transmit DATA_END packet.
  1331.                     ul_state <- UL_END.
  1332.                }
  1333.  
  1334.                EVENT: Receive UL_NAK_RESP packet. {
  1335.                     if error is unrecoverable mark file IMPOSSIBLE.
  1336.                     Transmit DATA_END packet.
  1337.                     ul_state <- UL_CMD_OK.
  1338.                }
  1339.  
  1340.                EVENT: DEFAULT{
  1341.                     if EVENT is not "data link terminated"
  1342.                           Terminate data link.
  1343.                     ul_state <- UL_UNINIT
  1344.                }
  1345.           }
  1346.  
  1347.           State UL_END {
  1348.  
  1349.                EVENT: Receive UL_ACK_RESP packet. {
  1350.                     Mark file COMPLETED.
  1351.                     ul_state <- UL_CMD_OK
  1352.                }
  1353.  
  1354.                EVENT: Receive UL_NAK_RESP packet. { 
  1355.                     If error is unrecoverable mark file IMPOSSIBLE.
  1356.                     ul_state <- UL_CMD_OK
  1357.                }
  1358.           }
  1359.  
  1360.  
  1361.           DOWNLINK STATE MACHINE
  1362.           The client's downlink state machine processes the following events:
  1363.                EVENT: User requests download
  1364.                EVENT: User requests directory
  1365.                EVENT: User requests selection
  1366.                EVENT: User requests abort
  1367.                EVENT: Receive DL_ABORTED_RESP packet.
  1368.                EVENT: Receive DL_COMPLETED_RESP packet.
  1369.                EVENT: Receive SELECT_RESP packet.
  1370.                EVENT: Receive LOGIN_RESP packet.
  1371.                EVENT: Receive DATA packet.
  1372.                EVENT: Receive DATA_END packet.
  1373.                EVENT: Receive DL_ERROR_RESP packet.
  1374.  
  1375.           The only user request which generates and event when not in DL_CMD_OK state is 
  1376.           ``user requests abort'', which is processed in the DL_DATA state.  All other 
  1377.           requests are ignored (perhaps queued) until dl_state is DL_CMD_OK.
  1378.           State DL_UNINIT{
  1379.           }
  1380.  
  1381.           State DL_CMD_OK{
  1382.  
  1383.                EVENT: User requests download {
  1384.                     Transmit DL_CMD packet.
  1385.                     dl_state := DL_WAIT.
  1386.                }
  1387.  
  1388.                EVENT: User requests directory {
  1389.                     Transmit DIR_LONG_CMD or DIR_SHORT_CMD packet.
  1390.                     dl_state := DL_DIR_WAIT.
  1391.                }
  1392.  
  1393.                EVENT: User requests selection {
  1394.                     Transmit SELECT_CMD packet.
  1395.                     dl_state := DL_SEL.
  1396.                }
  1397.  
  1398.                EVENT: User requests abort {
  1399.                     ignore.
  1400.                     dl_state := DL_CMD_OK
  1401.                }
  1402.  
  1403.                EVENT: DEFAULT{
  1404.                     if EVENT is not "data link terminated"
  1405.                           Terminate data link.
  1406.                     dl_state <- UL_UNINIT
  1407.                }
  1408.           }
  1409.  
  1410.           State DL_WAIT{
  1411.  
  1412.                EVENT: Receive DL_ERROR_RESP packet {
  1413.                     dl_state <- DL_CMD_OK.
  1414.                }
  1415.  
  1416.                EVENT: Receive DATA packet. {
  1417.                     Store data.
  1418.                     Mark file INCOMPLETE.
  1419.                     dl_state <- DL_DATA.
  1420.                }
  1421.  
  1422.                EVENT: Receive DATA_END packet. {
  1423.                     If file at client is ok {
  1424.                          Mark file DATA_OK.
  1425.                          Save <continue_offset> equal to file length.
  1426.                          Transmit DL_ACK_CMD.
  1427.                     }
  1428.                     Else {
  1429.                          Mark file INCOMPLETE.
  1430.                          Save <continue_offset> of 0.
  1431.                          Transmit DL_NAK_CMD.
  1432.                     }
  1433.                                    
  1434.                     dl_state <- DL_END.
  1435.                }
  1436.  
  1437.                EVENT: DEFAULT{
  1438.                     if EVENT is not "data link terminated"
  1439.                           Terminate data link.
  1440.                     dl_state <- UL_UNINIT
  1441.                }
  1442.           }
  1443.  
  1444.           State DL_DATA{
  1445.  
  1446.                EVENT: User requests abort {
  1447.                     Save current offset as <continue_offset>.
  1448.                     Transmit DL_NAK_CMD.
  1449.                     dl_state <- DL_ABORT.
  1450.                }
  1451.  
  1452.                EVENT: Receive DATA packet. {
  1453.                     Store data.
  1454.                     dl_state <- DL_DATA.
  1455.                }
  1456.  
  1457.                EVENT: Receive DATA_END packet. {
  1458.                     If file is ok at client 
  1459.                          Transmit DL_ACK_CMD packet.
  1460.                     Else
  1461.                          Transmit DL_NAK_CMD packet.
  1462.                     dl_state <- DL_END
  1463.                }
  1464.  
  1465.                EVENT: DEFAULT{
  1466.                     Save current offset as <continue_offset>.
  1467.                     if EVENT is not "data link terminated"
  1468.                           Terminate data link.
  1469.                     dl_state <- UL_UNINIT
  1470.                }
  1471.           }
  1472.  
  1473.           State DL_END{
  1474.  
  1475.                EVENT: Receive DL_ABORTED_RESP packet. {
  1476.                     dl_state <- DL_CMD_OK.
  1477.                }
  1478.  
  1479.                EVENT: Receive DL_COMPLETED_RESP packet. {
  1480.                     Mark file COMPLETE.
  1481.                     dl_state <- DL_CMD_OK.
  1482.                }
  1483.  
  1484.                EVENT: DEFAULT{
  1485.                     if EVENT is not "data link terminated"
  1486.                           Terminate data link.
  1487.                     dl_state <- UL_UNINIT
  1488.                }
  1489.           }
  1490.  
  1491.           State DL_ABORT{
  1492.  
  1493.                EVENT: Receive DATA packet. {
  1494.                     Ignore.
  1495.                     dl_state <- DL_ABORT.
  1496.                }
  1497.  
  1498.                EVENT: Receive DATA_END packet. {
  1499.                     dl_state <- DL_END.
  1500.                }
  1501.  
  1502.                EVENT: DEFAULT{
  1503.                     if EVENT is not "data link terminated"
  1504.                           Terminate data link.
  1505.                     dl_state <- UL_UNINIT
  1506.                }
  1507.           }
  1508.  
  1509.           State DL_DIR_WAIT{
  1510.  
  1511.                EVENT: Receive DATA packet. {
  1512.                     Send directory data to user.
  1513.                     dl_state <- DL_DIR_DATA.
  1514.                }
  1515.  
  1516.                EVENT: Receive DL_ERROR_RESP packet. {
  1517.                     dl_state <- DL_CMD_OK.
  1518.                }
  1519.  
  1520.                EVENT: DEFAULT{
  1521.                     if EVENT is not "data link terminated"
  1522.                           Terminate data link.
  1523.                     dl_state <- UL_UNINIT
  1524.                }
  1525.           }
  1526.  
  1527.           State DL_DIR_DATA{
  1528.  
  1529.                EVENT: Receive DATA packet. {
  1530.                     Send directory data to user.
  1531.                     dl_state <- DL_DIR_DATA
  1532.                }
  1533.  
  1534.                EVENT: Receive DATA_END packet.{
  1535.                     dl_state <- DL_CMD_OK
  1536.                }
  1537.  
  1538.                EVENT: DEFAULT{
  1539.                     if EVENT is not "data link terminated"
  1540.                           Terminate data link.
  1541.                     dl_state <- UL_UNINIT
  1542.                }
  1543.           }
  1544.  
  1545.           State DL_SEL{
  1546.  
  1547.                EVENT: Receive DL_ERROR_RESP packet. {
  1548.                     dl_state := DL_UNINIT
  1549.                }
  1550.  
  1551.                EVENT: Receive SELECT_RESP packet. {
  1552.                     dl_state := DL_UNINIT
  1553.                }
  1554.  
  1555.                EVENT: DEFAULT{
  1556.                     if EVENT is not "data link terminated"
  1557.                           Terminate data link.
  1558.                     dl_state <- UL_UNINIT
  1559.                }
  1560.           }
  1561.            
  1562.             APPENDIX D - Error Codes
  1563.             Value Name
  1564.               1   ER_ILL_FORMED_CMD
  1565.               2   ER_BAD_CONTINUE
  1566.               3   ER_SERVER_FSYS
  1567.               4   ER_NO_SUCH_FILE_NUMBER
  1568.               5   ER_SELECTION_EMPTY
  1569.               6   ER_MANDATORY_FIELD_MISSING
  1570.               7   ER_NO_PFH
  1571.               8   ER_POORLY_FORMED_SEL
  1572.               9   ER_ALREADY_LOCKED
  1573.               10  ER_NO_SUCH_DESTINATION
  1574.               11  ER_SELECTION_EMPTY
  1575.               12  ER_FILE_COMPLETE
  1576.               13  ER_NO_ROOM
  1577.               14  ER_BAD_HEADER
  1578.               15  ER_HEADER_CHECK
  1579.               16  ER_BODY_CHECK
  1580.  
  1581. 
  1582.